package com.mew.chess.core.game.dyj.game.message;

import cn.hutool.core.util.RandomUtil;
import com.mew.chess.core.game.dyj.game.common.DyjConstantValue;
import com.mew.common.config.NicknameUtil;
import com.mew.common.enm.UserType;
import com.mew.common.util.NumberUtil;
import com.mew.common.util.RandomIdUtil;
import com.mew.common.vo.UserSessionVO;
import io.netty.buffer.ByteBuf;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.util.HashMap;
import java.util.Map;


/**
 * @author dylin
 */
@Data
@ToString
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class UserMessage extends UserSessionVO {

    //主要记录机器人游戏次数
    private int playTimes;

    private long payment=-1;
    private long allBet;
    private Map<Integer,long[]> betRecord=new HashMap<>();

    @Override
    public void write(ByteBuf b) {
        //TODO 只发送brnn 需要的用户信息
        super.write(b);
    }

    public static UserMessage buildDyjRobotUserMessage(int min, String scope){
        UserMessage userMessage = new UserMessage();
        userMessage.buildRobotUserMessage(min,scope);
        userMessage.setPlayTimes(DyjConstantValue.ROBOT_MAX_PLAY_NUMBER);
        return userMessage;
    }
    public void userBet(int betType,long betNumber){
        updateGoldNumber(-betNumber);
        allBet+=betNumber;
        long[] r=betRecord.get(betType);
        if(null==r){
            betRecord.put(betType,new long[]{betNumber,0,0});
            return;
        }
        r[0]+=betNumber;
    }
    public void playTimes(){
        if(this.getUserType()==UserType.Robot.code()){
            playTimes--;
        }
    }

    public void clear(){
        payment=-1;
        allBet=0;
        betRecord.clear();
    }
}
